package com.axjy.controller;

import com.axjy.pojo.User;
import com.axjy.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Resource
    private PermissionService permissionService;


    @PostMapping("/login")
    public String login(String name, String pwd, Model model, HttpSession session){
        User loginUser=permissionService.login(name,pwd);
        if(loginUser==null){
            model.addAttribute("loginErr","用户名或密码错误");
            return "login";
        }
        session.setAttribute("loginUser",loginUser);
        return "redirect:/index";
    }


}
